using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Blople.GameScenes
{
    public class HighScoreScene : GameScene
    {
        protected Texture2D backgroundTexture;
        protected Texture2D blockTexture;
        protected SpriteFont largeFont;
        protected SpriteFont mediumFont;
        protected SpriteFont smallFont;

        protected HighScoreData highscores;

        public HighScoreScene(Game game, Texture2D backgroundTexture, Texture2D blockTexture, SpriteFont largeFont, SpriteFont mediumFont, SpriteFont smallFont) : base(game)
        {
            this.backgroundTexture = backgroundTexture;
            this.blockTexture = blockTexture;
            this.largeFont = largeFont;
            this.mediumFont = mediumFont;
            this.smallFont = smallFont;
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch sBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            sBatch.Draw(backgroundTexture, new Vector2(0, 0), Color.White);
            sBatch.Draw(blockTexture, new Vector2(25, 25), Color.White);
            sBatch.DrawString(largeFont, "Highscores", new Vector2((Game.Window.ClientBounds.Width - largeFont.MeasureString("Highscores").X) / 2, 50), Color.White);
            sBatch.DrawString(mediumFont, "Level 1", new Vector2((Game.Window.ClientBounds.Width - mediumFont.MeasureString("Level 1").X) / 2, 150), Color.White);
            int y = 160;
            int yStep = 1;
            for (int i = 0; i < highscores.Count; i++ )
            {
                if (i == 3) 
                {
                    sBatch.DrawString(mediumFont, "Level 2", new Vector2((Game.Window.ClientBounds.Width - mediumFont.MeasureString("Level 2").X) / 2, 300), Color.White);
                    y = 310;
                    yStep = 1;
                }

                if (i == 6)
                {
                    sBatch.DrawString(mediumFont, "Level 3", new Vector2((Game.Window.ClientBounds.Width - mediumFont.MeasureString("Level 3").X) / 2, 450), Color.White);
                    y = 460;
                    yStep = 1;
                }

                sBatch.DrawString(smallFont, highscores.Name[i] + ": " + highscores.Score[i], new Vector2((Game.Window.ClientBounds.Width - mediumFont.MeasureString(highscores.Name[i] + ": " + highscores.Score[i]).X) / 2, y + (30 * yStep)), Color.White);
 
                yStep++;

                base.Draw(gameTime);
            }
            
        }

        public override void Show()
        {
            highscores = HighScoreData.LoadHighScores();
            base.Show();
        }
    }
}
